home *** CD-ROM | disk | FTP | other *** search
- <HTMLtool>This script just does some calculations on your weight and height.</HTMLtool>
- <SCRIPT LANGUAGE="JavaScript">
- <!--
-
- function getHeight(sex, age, height) {
- height = Math.round(height)
- var height5 = 0
- var height50 = 0
- if (age == 2) {
- height50 = 87
- height5 = 82
- } else
- if (age == 3) {
- height50 = 95
- height5 = 90
- } else
- if (age == 4) {
- height50 = 102
- height5 = 95
- } else
- if (age == 5) {
- height50 = 109
- height5 = 101
- } else
- if (age == 6) {
- height50 = 114
- height5 = 107
- } else
- if (age == 7) {
- height50 = 120
- height5 = 112
- } else
- if (age == 8) {
- height50 = 126
- height5 = 118
- } else
- if (age == 9) {
- height50 = 131
- height5 = 121
- } else
- if (age == 10) {
- height50 = 137
- height5 = 127
- } else
- if (age == 11) {
- height50 = 143
- height5 = 131
- } else
- if (sex == "f") {
- if (age == 12) {
- height50 = 150
- height5 = 140
- } else
- if (age == 13) {
- height50 = 157
- height5 = 145
- } else
- if (age == 14) {
- height50 = 160
- height5 = 148
- } else
- if (age == 15) {
- height50 = 162
- height5 = 150
- } else
- if (age == 16) {
- height50 = 162
- height5 = 151
- } else
- if (age == 17) {
-
- height50 = 163
- height5 = 153
- } else
- if (age == 18) {
- height50 = 164
- height5 = 154
- }
- } else
- if (age == 12) {
- height50 = 150
- height5 = 137
- } else
- if (age == 13) {
- height50 = 156
- height5 = 142
- } else
- if (age == 14) {
- height50 = 162
- height5 = 148
- } else
- if (age == 15) {
- height50 = 168
- height5 = 155
- } else
- if (age == 16) {
- height50 = 174
- height5 = 160
- } else
- if (age == 17) {
- height50 = 175
- height5 = 165
- } else
- if (age == 18) {
- height50 = 176
- height5 = 165
- }
- var percent = (height - height5) * (50 - 5) / (height50 - height5) + 5
- return percent
- }
-
- // Returns the weight percentage (50% is
- // average...), according to the given
- // sex, age, and actual weight in kg
- /////////////////////////////////////////
-
- function getWeight(sex, age, weight) {
- weight = Math.round(weight)
- var weight5 = 0
- var weight50 = 0
- if (age == 2) {
- weight50 = 12
- weight5 = 10
- } else
- if (age == 3) {
- weight50 =14
- weight5 = 12
- } else
- if (age == 4) {
- weight50 = 16
- weight5 = 14
- } else
- if (age == 5) {
- weight50 = 18
- weight5 = 15
- } else
- if (age == 6) {
- weight50 = 20
- weight5 = 17
- } else
- if (age == 7) {
- weight50 = 22
- weight5 = 18
- } else
- if (age == 8) {
- weight50 = 25
- weight5 = 20
- } else
- if (age == 9) {
- weight50 = 29
- weight5 = 22
- } else
- if (sex == "f") {
- if (age == 10) {
- weight50 = 32
- weight5 = 25
- } else
- if (age == 11) {
- weight50 = 37
- weight5 = 27
- } else
- if (age == 12) {
- weight50 = 41
- weight5 = 30
- } else
- if (age == 13) {
- weight50 = 46
- weight5 = 34
- } else
- if (age == 14) {
- weight50 = 50
- weight5 = 38
- } else
- if (age == 15) {
- weight50 = 53
- weight5 = 40
- } else
- if (age == 16) {
- weight50 = 56
- weight5 = 43
- } else
- if (age == 17) {
- weight50 = 57
- weight5 = 45
- } else
- if (age == 18) {
- weight50 = 57
- weight5 = 46
- }
- } else
- if (age == 10) {
- weight50 = 24
- weight5 = 31
- } else
- if (age == 11) {
- weight50 = 35
- weight5 = 27
- } else
- if (age == 12) {
- weight50 = 40
- weight5 = 30
- } else
- if (age == 13) {
- weight50 = 46
- weight5 = 35
- } else
- if (age == 14) {
- weight50 = 51
- weight5 = 38
- } else
- if (age == 15) {
- weight50 = 57
- weight5 = 44
- } else
- if (age == 16) {
- weight50 = 62
-
- weight5 = 48
- } else
- if (age == 17) {
- weight50 = 67
- weight5 = 53
- } else
- if (age == 18) {
- weight50 = 69
- weight5 = 55
- }
- var percent = (weight - weight5) * (50 - 5) / (weight50 - weight5) + 5
- return percent
- }
-
- // Creates a comment according to the
- // height, weight, age, sex, and a
- // computed overall caculation. Also
- // displays a disclaimer. It optionally
- // displays the "scientific" results
- /////////////////////////////////////////
-
- function printResult(height, weight, sex, age) {
- var heightAdj = ""
- var weightAdj = ""
- var ageAdj = ""
-
- var sexAdj = ""
- var gradeAdj = ""
- var grade = 0
- var propWeight = weight / height
- if (height > 70) {
- heightAdj = "tall"
- grade += 2
- } else
- if (height < 30) {
- heightAdj = "short"
- grade += 1
- } else {
- heightAdj = "medium-height"
- grade += 3
- }
- if (propWeight > 2) {
- weightAdj = "over-weight"
- grade += 1
- } else
- if (propWeight < 0.5) {
- weightAdj = "slim"
- grade += 2
- } else {
- weightAdj = "medium-weight"
- grade += 3
- }
- ageAdj = ageInput + "-year old"
- if (grade >= 5)
- gradeAdj = "great-looking"
- else
- if (grade <= 2)
- gradeAdj = "ackward-looking"
- else
- gradeAdj = "fine-looking"
- sexAdj = (sex == "f") ? "female" : "male"
- var finalMessage = "You are a " + heightAdj + ", "
- finalMessage += weightAdj + ", " + gradeAdj + " "
- finalMessage += ageAdj + " " + sexAdj + "."
- alert(finalMessage)
- if (confirm("Are you interested in scientific results?")) {
- scMessage = "height = " + Math.round(height)
- scMessage +="%\rweight = " + Math.round(weight)
- scMessage += "%\rweight/height = " + propWeight
- alert(scMessage)
- } else
- if (grade <= 4)
- alert("Good idea!")
- var notice = "Thank you for using the JavaScript weight "
- notice += "and height calculator. All calculations are "
- notice += "done according to the child-development graph "
- notice += "in \"Compton's Encyclopedia\". We appologize "
- notice += "if you were insulted by the comments -- that "
- notice += "was not our intention. We used them to demonstrate "
- notice += "various JavaScript scripting techniques."
- alert(notice)
- }
-
- // converts weight and height from
- // english system to metric system.
- /////////////////////////////////////////
-
- function convertInput() {
- weightInput *= 0.45359
- heightInput *= 2.54
- }
-
- // Global statements to receive input
- // and call functions
- /////////////////////////////////////////
-
- var sex = prompt("Enter sex ((m)ale or (f)emale):", "")
- var ageInput = parseInt(prompt("Enter age in years (minimum = 2):", ""))
- ageInput = Math.round(ageInput)
- var systemMessage = "Whould you like to use the (m)etric system "
- systemMessage += "or the (e)nglish one?"
- var system = prompt(systemMessage, "m")
- var heightUnit = (system == "m") ? "centimeters" : "inches"
- var weightUnit = (system == "m") ? "kilograms" : "pounds"
- var heightInput = prompt("Enter height in " + heightUnit + ":", "")
- heightInput = parseInt(heightInput)
- var weightInput = prompt("Enter weight in " + weightUnit + ":", "")
- weightInput = parseInt(weightInput)
- if (system == "e")
- convertInput()
- if (ageInput > 18)
- var age = 18
- else
- if (ageInput < 2)
- var age = 2
- else
- var age = ageInput
- var heightPer = getHeight(sex, age, heightInput)
- var weightPer = getWeight(sex, age, weightInput)
- heightPer = (heightPer < 1) ? 1 : heightPer
- heightPer = (heightPer > 99) ? 99 : heightPer
- weightPer = (weightPer < 1) ? 1 : weightPer
- weightPer = (weightPer > 99) ? 99 : weightPer
- printResult(heightPer, weightPer, sex, age)
-
- // -->
- </SCRIPT>